home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3957 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.4 KB  |  95 lines

  1. Path: news.umbc.edu!nobody
  2. From: helfrick@cs.umbc.edu (Dave Helfrick.)
  3. Newsgroups: comp.sys.sgi.hardware,comp.lang.c++
  4. Subject: Help with serial/tty2 communication (write ok, read NOT).
  5. Date: 26 Jan 1996 17:34:50 -0500
  6. Organization: University of Maryland Baltimore County
  7. Distribution: na
  8. Message-ID: <4ebkuaINNdqp@retriever.cs.umbc.edu>
  9. NNTP-Posting-Host: retriever.cs.umbc.edu
  10. NNTP-Posting-User: helfrick
  11.  
  12.  
  13.  
  14. I am running on an Impact, and am trying to write a C++ class
  15. (wrapper for C code) to communicate with a serial port.
  16.  
  17. I can write ok, but reading is not working.
  18.  
  19. Here is the read and write methods, plus the constructor...
  20. CONSTRUCTOR...............
  21. HtRawSerial::HtRawSerial(char *portName, int baudRate)
  22. {
  23.     _goodOpen = TRUE;
  24.     _goodClose = FALSE;
  25.  
  26.     if ((TTyfd = open(portName, (O_RDWR | O_NONBLOCK))) < 0)
  27.       //    if ((TTyfd = open(portName, (O_RDWR | O_NDELAY))) < 0)
  28.     {
  29. #        ifndef FOR_PERFORMER
  30.             cout << "*** Unable to open" << portName << endl;
  31. #        else
  32.             printf("*** Unable to open '%s'.\n", portName);
  33. #        endif
  34.         _goodOpen = FALSE;
  35.     }
  36.  
  37.     // Initialize the serial port I/O control structures.
  38.     if (!ioctl_get(TTyfd, &OldTermIO))
  39.     {
  40.         printf("***Failed to get old terminal\n");
  41.         _goodOpen = FALSE;
  42.     }
  43.  
  44.     if (!ioctl_get(TTyfd, &NewTermIO))
  45.     {
  46.         printf("***Failed to get new terminal\n");
  47.         _goodOpen = FALSE;
  48.     }
  49.  
  50.     ioctl_prep_init_raw(&NewTermIO);
  51.     ioctl_prep_baud(&NewTermIO, baudRate);
  52.  
  53.     /*
  54.     * Configure the serial port and console.
  55.     */
  56.     if (!ioctl_set(TTyfd, &NewTermIO))
  57.     {
  58.         printf("***Failed ioctl_set(TTyfd, &NewTermIO)\n");
  59.         _goodOpen = FALSE;
  60.     }
  61.     //    openFlag = _goodOpen;
  62. }
  63. -------------------------------------------------
  64. WRITE.....................................
  65. /*^============================================================================
  66.   RETURNS:       TRUE if successful, FALSE otherwise.
  67.   PARAMETERS:    The character you are writing
  68. =*^=============*/
  69. int HtRawSerial::writeByte(unsigned char &byte)
  70. {
  71.     if (write(TTyfd, &byte, 1) > 0)
  72.         return(TRUE);
  73.     return(FALSE);
  74. }
  75.  
  76. ------------------------------------------------------
  77. READ  <THIS IS WHAT DOES NOT WORK!!!!!!!!!>
  78. /*^============================================================================
  79.   RETURNS:       TRUE if successful, FALSE otherwise.
  80.   PARAMETERS:    The character you are reading
  81. =*^=============*/
  82. int HtRawSerial::readByte(unsigned char &byte)
  83. {
  84.     if (read(TTyfd, &byte, 1) > 0)
  85.         return(TRUE);
  86.     return(FALSE);
  87. }
  88.  
  89.  
  90.  
  91. -- 
  92.                 - Dave
  93. helfrick@cs.umbc.edu
  94.  
  95.